package com.chagee.store.operation.server.controller;

import com.alibaba.fastjson.JSON;
import com.chagee.base.utils.HttpResponse;
import com.chagee.base.utils.HttpResponseUtil;
import com.chagee.store.operation.api.request.WorkOrderRequest;
import com.chagee.store.operation.common.exception.BizErrorCode;
import com.chagee.store.operation.common.utils.CommonUtil;
import com.chagee.store.operation.server.facade.StoreOrderEvaluateFacade;
import com.chagee.store.operation.server.model.param.QueryEvaluateListParam;
import com.chagee.store.operation.server.model.param.StoreInfoParam;
import com.chagee.store.operation.server.model.vo.EvaluateInfoResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * pc 端打烊工单评价
 *
 * @Author : hk
 * @Date : 2024/4/29
 */

@Slf4j
@RestController
@RequestMapping("/orderEvaluate")
public class StoreOrderEvaluateController {

	@Resource
	private StoreOrderEvaluateFacade storeOrderEvaluateFacade;

	/**
	 * 打烊评价列表
	 *
	 * @param param
	 * @return
	 */
	@PostMapping("/list")
	@ApiOperation("打烊评价列表")
	public HttpResponse<List<EvaluateInfoResponse>> list(@RequestBody @Valid QueryEvaluateListParam param) {
		log.info("store_StoreOrderEvaluateController_list_request:{}, auth:{}", JSON.toJSONString(param), JSON.toJSONString(AuthUtil.getUser()));
		if (StringUtils.isNotBlank(CommonUtil.validate(param))) {
			return HttpResponseUtil.build(null, BizErrorCode.REQUEST_VALID_FAILED.getErrorCode(), CommonUtil.validate(param));
		}
		List<EvaluateInfoResponse> result = storeOrderEvaluateFacade.list(param);
		return HttpResponseUtil.success(result);
	}

	/**
	 * 工单评价导出
	 *
	 * @param param request
	 * @return resp
	 */
	@PostMapping("/evaluateExport")
	@ApiOperation("工单评价导出")
	public void evaluateExport(@RequestBody WorkOrderRequest param, HttpServletRequest request, HttpServletResponse response, ModelMap map) {
		log.info("store_StoreOrderEvaluateController_evaluateExport_request:{}, auth:{}", JSON.toJSONString(param), JSON.toJSONString(AuthUtil.getUser()));
		storeOrderEvaluateFacade.evaluateExport(param,request, response,map);
		//return HttpResponseUtil.success(null);
	}
}
